home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / as2db1 / general.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1994-01-07  |  31.7 KB  |  964 lines

  1. VERSION 2.00
  2. Begin Form Form1 
  3.    AutoRedraw      =   -1  'True
  4.    BackColor       =   &H00C0C0C0&
  5.    BorderStyle     =   1  'Fixed Single
  6.    Caption         =   "ASC2MDB"
  7.    ClientHeight    =   4905
  8.    ClientLeft      =   1560
  9.    ClientTop       =   1920
  10.    ClientWidth     =   5400
  11.    FillStyle       =   0  'Solid
  12.    Height          =   5595
  13.    Icon            =   GENERAL.FRX:0000
  14.    Left            =   1500
  15.    LinkTopic       =   "Form1"
  16.    MaxButton       =   0   'False
  17.    ScaleHeight     =   4905
  18.    ScaleWidth      =   5400
  19.    Top             =   1290
  20.    Width           =   5520
  21.    Begin CommandButton cmdTranslate 
  22.       Caption         =   "&Start"
  23.       Default         =   -1  'True
  24.       Height          =   375
  25.       Left            =   3600
  26.       TabIndex        =   0
  27.       Top             =   3240
  28.       Width           =   1455
  29.    End
  30.    Begin CommandButton cmdExit 
  31.       Cancel          =   -1  'True
  32.       Caption         =   "E&xit"
  33.       Height          =   375
  34.       Left            =   3600
  35.       TabIndex        =   1
  36.       Top             =   3840
  37.       Width           =   1455
  38.    End
  39.    Begin Frame Frame1 
  40.       BackColor       =   &H00C0C0C0&
  41.       Height          =   495
  42.       Left            =   -10
  43.       TabIndex        =   15
  44.       Top             =   4440
  45.       Width           =   5425
  46.       Begin SSPanel pnlStatus 
  47.          BevelOuter      =   1  'Inset
  48.          FontBold        =   -1  'True
  49.          FontItalic      =   -1  'True
  50.          FontName        =   "MS Sans Serif"
  51.          FontSize        =   8.25
  52.          FontStrikethru  =   0   'False
  53.          FontUnderline   =   0   'False
  54.          ForeColor       =   &H000000FF&
  55.          Height          =   255
  56.          Left            =   80
  57.          TabIndex        =   16
  58.          Top             =   165
  59.          Width           =   5260
  60.       End
  61.    End
  62.    Begin SSFrame Frame3D5 
  63.       Caption         =   "Replace Mode:"
  64.       ForeColor       =   &H00000000&
  65.       Height          =   615
  66.       Left            =   120
  67.       TabIndex        =   14
  68.       Top             =   2280
  69.       Width           =   5175
  70.       Begin Label lblReplaceMode 
  71.          BackColor       =   &H00C0C0C0&
  72.          Height          =   255
  73.          Left            =   120
  74.          TabIndex        =   9
  75.          Top             =   240
  76.          Width           =   4815
  77.       End
  78.    End
  79.    Begin SSFrame Frame3D4 
  80.       Caption         =   "Table Destination: "
  81.       ForeColor       =   &H00000000&
  82.       Height          =   615
  83.       Left            =   120
  84.       TabIndex        =   12
  85.       Top             =   1560
  86.       Width           =   5175
  87.       Begin Label lblCurrTable 
  88.          BackColor       =   &H00C0C0C0&
  89.          Height          =   255
  90.          Left            =   120
  91.          TabIndex        =   13
  92.          Top             =   240
  93.          Width           =   4815
  94.       End
  95.    End
  96.    Begin SSFrame frameTableProcessing 
  97.       Caption         =   "Table Processing"
  98.       ForeColor       =   &H00000000&
  99.       Height          =   1335
  100.       Left            =   120
  101.       TabIndex        =   10
  102.       Top             =   3000
  103.       Width           =   3135
  104.       Begin Gauge Gauge1 
  105.          Autosize        =   -1  'True
  106.          BackColor       =   &H0080FFFF&
  107.          ForeColor       =   &H000000FF&
  108.          Height          =   360
  109.          InnerBottom     =   -5
  110.          InnerLeft       =   -5
  111.          InnerRight      =   -5
  112.          InnerTop        =   -5
  113.          Left            =   240
  114.          Max             =   100
  115.          NeedleWidth     =   1
  116.          TabIndex        =   11
  117.          Top             =   360
  118.          Visible         =   0   'False
  119.          Width           =   2655
  120.       End
  121.       Begin Label lblElapsedTime 
  122.          Alignment       =   2  'Center
  123.          BackStyle       =   0  'Transparent
  124.          Height          =   255
  125.          Left            =   120
  126.          TabIndex        =   6
  127.          Top             =   360
  128.          Visible         =   0   'False
  129.          Width           =   2775
  130.       End
  131.       Begin Label lblRecCount 
  132.          Alignment       =   2  'Center
  133.          BackStyle       =   0  'Transparent
  134.          Height          =   255
  135.          Left            =   120
  136.          TabIndex        =   7
  137.          Top             =   960
  138.          Width           =   2775
  139.       End
  140.       Begin Label lblDBCount 
  141.          Alignment       =   2  'Center
  142.          BackStyle       =   0  'Transparent
  143.          Height          =   255
  144.          Left            =   120
  145.          TabIndex        =   8
  146.          Top             =   660
  147.          Visible         =   0   'False
  148.          Width           =   2775
  149.       End
  150.    End
  151.    Begin SSFrame Frame3D2 
  152.       Caption         =   "Database Destination File:"
  153.       ForeColor       =   &H00000000&
  154.       Height          =   615
  155.       Left            =   120
  156.       TabIndex        =   4
  157.       Top             =   840
  158.       Width           =   5175
  159.       Begin Label lblCurrDatabase 
  160.          BackColor       =   &H00C0C0C0&
  161.          Height          =   255
  162.          Left            =   120
  163.          TabIndex        =   5
  164.          Top             =   240
  165.          Width           =   4815
  166.       End
  167.    End
  168.    Begin SSFrame Frame3D1 
  169.       Caption         =   "ASCII Source File:"
  170.       ForeColor       =   &H00000000&
  171.       Height          =   615
  172.       Left            =   120
  173.       TabIndex        =   3
  174.       Top             =   120
  175.       Width           =   5175
  176.       Begin Label lblCurrInput 
  177.          BackColor       =   &H00C0C0C0&
  178.          Height          =   255
  179.          Left            =   120
  180.          TabIndex        =   2
  181.          Top             =   240
  182.          Width           =   4815
  183.       End
  184.    End
  185.    Begin CommonDialog cmdlg1 
  186.       Left            =   360
  187.       Top             =   3240
  188.    End
  189.    Begin Menu mnuFile 
  190.       Caption         =   "&File"
  191.       Begin Menu mnuFileExit 
  192.          Caption         =   "E&xit"
  193.       End
  194.    End
  195.    Begin Menu mnuEdit 
  196.       Caption         =   "&Edit"
  197.       Begin Menu mnuEditInput 
  198.          Caption         =   "&ASCII Source"
  199.       End
  200.       Begin Menu mnuEditMDB 
  201.          Caption         =   "&MDB Destination"
  202.       End
  203.       Begin Menu mnuEditTable 
  204.          Caption         =   "&Table Destination"
  205.       End
  206.       Begin Menu mnuSep0 
  207.          Caption         =   "-"
  208.       End
  209.       Begin Menu mnuEditReplMode 
  210.          Caption         =   "&Replace Mode"
  211.       End
  212.    End
  213.    Begin Menu mnuHelp 
  214.       Caption         =   "&Help"
  215.       Begin Menu mnuHelpContents 
  216.          Caption         =   "Help &Contents"
  217.       End
  218.       Begin Menu mnuSep1 
  219.          Caption         =   "-"
  220.       End
  221.       Begin Menu mnuHelpAbout 
  222.          Caption         =   "&About"
  223.       End
  224.    End
  225. ' ASC2MDB
  226. 'copyright 1993 by Richard Curzon
  227. 'May be used freely as a personal utility but may not
  228. '  be sold without express permission from the author
  229. 'May be copied for personal use under these terms
  230. Option Explicit
  231. Dim InFileNum As Integer 'input file number, for emergency close
  232. Dim localErrFileName     'copy of gcErrFileName that may be modified
  233.              'by command line
  234. Dim AscErrorFlag As Integer
  235. Sub AddNewOrSeekEdit (InFileLine)
  236.     Select Case ReplaceMode
  237.     Case Is < 4
  238.     gTabOut.AddNew
  239.     Case Else
  240.     gTabOut.Index = Mode45Index()    'func in SPECIFIC.BAS
  241.     gTabOut.Seek "=", Mid(InFileLine, gIOFld(Mode345Key()).inStart, gIOFld(Mode345Key()).inLength)
  242.     If gTabOut.NoMatch And ReplaceMode = 4 Then
  243.         gTabOut.AddNew
  244.     Else
  245.         gTabOut.Edit
  246.     End If
  247.     End Select
  248. End Sub
  249. Private Sub CheckBlockDeleteKey (InFileLine)
  250.     'Replace Mode 3 only, block delete
  251.     Dim SQL
  252.     Dim Msg, LogMsg
  253.     Dim CandidateValue
  254.     Dim KeyFound As Integer
  255.     Dim TestBDKey As Integer
  256.     Dim ds As DynaSet
  257.     pnlStatus = "deleting block...": DoEvents
  258.     TestBDKey = Mode345Key()  'Func in SPECIFIC.BAS
  259.     CandidateValue = Mid(InFileLine, gIOFld(TestBDKey).inStart, gIOFld(TestBDKey).inLength)
  260.     If gIOFld(TestBDKey).dbType = DB_TEXT Then CandidateValue = "'" & CandidateValue & "'"
  261.     On Error GoTo BDError
  262.     pnlStatus = "counting records...": DoEvents
  263.     SQL = "SELECT count([" & gIOFld(TestBDKey).dbName
  264.     SQL = SQL & "]) as itemCount FROM [" & gTabOut
  265.     SQL = SQL & "] WHERE [" & gIOFld(TestBDKey).dbName
  266.     SQL = SQL & "] = " & CandidateValue
  267.     Set ds = thisDb.CreateDynaset(SQL)
  268.     pnlStatus = "finished counting records...": DoEvents
  269.     LogMsg = "field used as delete attribute: " & gIOFld(TestBDKey).dbName & NL
  270.     LogMsg = LogMsg & "delete criterion: " & CandidateValue & NL
  271.     LogMsg = LogMsg & "records matching delete criterion: " & ds!itemCount & NL
  272.     Logline LogMsg
  273.     'allow the user to abort anyway...
  274.     Msg = ds!itemCount & " records will be deleted from the" & NL
  275.     Msg = Msg & "existing table """ & lblCurrTable & """" & NL
  276.     Msg = Msg & "existing file """ & lblCurrDatabase & """" & NL
  277.     Msg = Msg & "  where the field """ & gIOFld(TestBDKey).dbName & """" & NL
  278.     Msg = Msg & "  is """ & CandidateValue & """" & NL & NL
  279.     Msg = Msg & "DO YOU WANT TO ABORT?"
  280.     ans = MsgBox(Msg, MB_YESNO + MB_APPLMODAL + MB_ICONQUESTION, "Block Delete Abort Dialog")
  281.     If ans = idyes Then
  282.       gTabOut.Close
  283.       ds.Close
  284.       thisDb.Close
  285.       Logline "User aborted." & NL
  286.       End
  287.     End If
  288.     'Okay, if you insist -- say good bye to your records...
  289.     pnlStatus = "deleting old records...": DoEvents
  290.     SQL = "DELETE from [" & gTabOut & "] WHERE ["
  291.     SQL = SQL & gIOFld(TestBDKey).dbName
  292.     SQL = SQL & "] = " & CandidateValue
  293.     thisDb.Execute SQL
  294.     pnlStatus = "processing input records...": DoEvents
  295.     On Error GoTo 0
  296.     Exit Sub
  297. BDError:
  298.     If Err = 3021 Then Resume Next
  299.     '3021: No current record: failed to find a
  300.     '       record meeting criteria
  301.     Msg = "CheckBlockDeleteError:" & NL
  302.     Msg = Msg & Err & " : " & Error & NL
  303.     Msg = Msg & "Suggestion: Check 1st record of input file" & NL
  304.     MsgBox Msg
  305.     End
  306. End Sub
  307. Sub CheckFields ()
  308.     'this SUB shouldn't need customizing
  309.     Dim Msg
  310.     Dim ErrCount
  311.     Dim Looper As Integer
  312.     Msg = "Checking field definitions..." & NL
  313.     ErrCount = 0
  314.     On Error GoTo CheckError0
  315.     For Looper = 1 To UBound(gIOFld)
  316.     If Len(gIOFld(Looper).dbName) = 0 Then
  317.         Msg = Msg & "IO Fld " & Looper & " may be missing" & NL
  318.         Error 32000
  319.     End If
  320.     If gIOFld(Looper).dbType = DB_TEXT Then
  321.     End If
  322.     Select Case gIOFld(Looper).dbType
  323.     Case DB_BOOLEAN
  324.         If gIOFld(Looper).dbSize <> 1 Then
  325.         Msg = Msg & "DB_BOOLEAN S/B dbSize 1" & NL
  326.         Error 32000
  327.         End If
  328.     Case DB_BYTE
  329.         If gIOFld(Looper).dbSize <> 1 Then
  330.         Msg = Msg & "DB_BYTE s/b dbSize 1" & NL
  331.         Error 32000
  332.         End If
  333.     Case DB_INTEGER
  334.         If gIOFld(Looper).dbSize <> 2 Then
  335.         Msg = Msg & "DB_INTEGER s/b dbSize 2" & NL
  336.         Error 32000
  337.         End If
  338.     Case DB_CURRENCY
  339.         If gIOFld(Looper).dbSize <> 8 Then
  340.         Msg = Msg & "DB_CURRENCY s/b dbSize 8" & NL
  341.         Error 32000
  342.         End If
  343.     Case DB_SINGLE
  344.         If gIOFld(Looper).dbSize <> 4 Then
  345.         Msg = Msg & "DB_SINGLE s/b dbSize 4" & NL
  346.         Error 32000
  347.        End If
  348.     Case DB_DOUBLE
  349.         If gIOFld(Looper).dbSize <> 8 Then
  350.         Msg = Msg & "DB_DOUBLE s/b dbSize 8" & NL
  351.         Error 32000
  352.         End If
  353.     Case DB_LONG
  354.         If gIOFld(Looper).dbSize <> 4 Then
  355.         Msg = Msg & "DB_LONG s/b dbSize 4" & NL
  356.         Error 32000
  357.         End If
  358.     Case DB_DATE
  359.         If gIOFld(Looper).dbSize <> 8 Then
  360.         Msg = Msg & "DB_DATE s/b dbSize 8" & NL
  361.         Error 32000
  362.         End If
  363.     Case DB_TEXT
  364.         If gIOFld(Looper).dbSize > 255 Or gIOFld(Looper).dbSize < 1 Then
  365.         Msg = Msg & "DB_TEXT s/b dbSize 1-255" & NL
  366.         Error 32000
  367.         End If
  368.         If gIOFld(Looper).dbSize <> gIOFld(Looper).inLength Then
  369.         Msg = Msg & "DB_TEXT length discrepancy" & NL
  370.         Error 32000
  371.         End If
  372.     Case DB_LONGBINARY
  373.         If gIOFld(Looper).dbSize <> 0 Then
  374.         Msg = Msg & "DB_LONGBINARY s/b dbSize 0" & NL
  375.         Error 32000
  376.         End If
  377.     Case DB_MEMO
  378.         If gIOFld(Looper).dbSize <> 0 Then
  379.         Msg = Msg & "DB_MEMO s/b dbSize 0" & NL
  380.         Error 32000
  381.         End If
  382.     Case Else
  383.         Msg = Msg & "Not a valid database dbType: " & gIOFld(Looper).dbType & NL
  384.         Error 32000
  385.     End Select
  386.     Next Looper
  387.     If ErrCount > 0 Then
  388.     Msg = "Errors, please fix before continuing"
  389.     Beep
  390.     MsgBox Msg
  391.     End If
  392.     Exit Sub
  393. CheckError0:
  394.     ErrCount = ErrCount + 1
  395.     Msg = "Checking field definitions..." & NL
  396.     Msg = Msg & "Check figures in Field """ & gIOFld(Looper).dbName & """"
  397.     MsgBox Msg
  398.     Resume Next  'aborts later if Errcount > 0
  399. End Sub
  400. Sub CheckIndexes ()
  401.     'this SUB shouldn't need customizing
  402.     Dim Msg
  403.     Dim Looper As Integer
  404.     Dim ErrCount As Integer
  405.     Dim Primarycount As Integer
  406.     Dim FldCount As Integer
  407.     Msg = "Checking index definitions..." & NL
  408.     Primarycount = 0
  409.     ErrCount = 0
  410.     On Error GoTo CheckError1
  411.     If UBound(gIndexPtrn) = 0 Then Exit Sub
  412.     For Looper = 1 To UBound(gIndexPtrn)
  413.     If Len(gIndexPtrn(Looper).Name) = 0 Then
  414.         Msg = "Index " & Looper & " may be missing" & NL
  415.         Error 32000
  416.     End If
  417.     If gIndexPtrn(Looper).Primary = True Then
  418.         Primarycount = Primarycount + 1
  419.         If gIndexPtrn(Looper).Unique = False Then MsgBox "NOTE: " & gIndexPtrn(Looper).Name & " Index is Primary, so will be Unique!"
  420.     End If
  421.     CheckThisKey (Looper)
  422.     If Primarycount > 1 Then
  423.     Msg = "More than one index is marked ""Primary""" & NL
  424.     Primarycount = 1  ' to trap next one too
  425.     Error 32000
  426.     End If
  427.     Next Looper
  428.     If ErrCount > 0 Then
  429.     Msg = "Errors, please fix before continuing"
  430.     Beep
  431.     MsgBox Msg
  432.     End If
  433.     Exit Sub
  434. CheckError1:
  435.     ErrCount = ErrCount + 1
  436.     Msg = Msg & "Check figures in Key """ & gIndexPtrn(Looper).Name & """"
  437.     MsgBox Msg
  438.     Msg = "checking index definitions..." & NL
  439.     Resume Next   'aborts later if errcount > 0
  440. End Sub
  441. Private Sub CheckThisKey (Ind)
  442.     Dim Msg
  443.     Dim iInd As Integer         'index counter
  444.     Dim iFld As Integer        'index counter
  445.     Dim ErrCount As Integer
  446.     Dim iKeys() As String     ' array of keys in index
  447.     Dim cKeys As Integer      ' count the keys
  448.     Dim KeyFound As Integer 'is the index key a valid field name
  449.     Dim iMarker As Integer    ' mark off the dbnames in key
  450.     Dim remKeys As String     ' working temporary
  451.     'sample input: gIndexPtrn(3).Fields = "DTN;Phone"
  452.     cKeys = 1
  453.     ReDim iKeys(cKeys)
  454.     remKeys = gIndexPtrn(Ind).Fields
  455.     iMarker = InStr(remKeys, ";")
  456.     Msg = ""
  457.     On Error GoTo CheckError2
  458.     'make the array of keys
  459.     Do While iMarker > 0
  460.     iKeys(cKeys) = Mid(remKeys, 1, iMarker - 1)
  461.     remKeys = Mid(remKeys, iMarker + 1, Len(remKeys))
  462.     cKeys = cKeys + 1
  463.     ReDim Preserve iKeys(cKeys)
  464.     iMarker = InStr(remKeys, ";")
  465.     Loop
  466.     iKeys(cKeys) = remKeys
  467.     'compare the array to the actual fields in the database
  468.     For iInd = 1 To cKeys
  469.     KeyFound = False
  470.     For iFld = 1 To UBound(gIOFld)
  471.         If iKeys(iInd) = gIOFld(iFld).dbName Then
  472.         KeyFound = True
  473.         Exit For
  474.         End If
  475.     Next iFld
  476.     If Not KeyFound Then
  477.         Msg = "Key not found: """ & iKeys(iInd) & """" & NL
  478.         Msg = Msg & "Index Name """ & gIndexPtrn(Ind).Name & """" & NL
  479.         Msg = Msg & "Index Number " & Ind & NL
  480.         Error 32000
  481.     End If
  482.     If Len(iKeys(cKeys)) < 1 Then
  483.         Msg = "Null key for index """ & gIndexPtrn(Ind).Name & """" & NL
  484.         Msg = Msg & "Index Number " & Ind & NL
  485.         Error 32000
  486.     End If
  487.     Next iInd
  488.     If ErrCount > 0 Then
  489.     Msg = "Errors, please fix before continuing"
  490.     Beep
  491.     MsgBox Msg
  492.     End If
  493.     Exit Sub
  494. CheckError2:
  495.     ErrCount = ErrCount + 1
  496.     MsgBox Msg
  497.     Resume Next
  498. End Sub
  499. Sub cmdExit_Click ()
  500.     If Not gRunning Then
  501.     Unload Me
  502.     Else
  503.     ans = MsgBox("Job is running, do you want to abort?", MB_YESNO + MB_APPLMODAL + MB_ICONQUESTION, "Exit button pushed")
  504.     If ans = idyes Then
  505.         Logline "User Aborted." & NL
  506.         Close InFileNum
  507.         If Not gTabOut Is Nothing Then
  508.         gTabOut.Close
  509.         End If
  510.         If Not thisDb Is Nothing Then
  511.         thisDb.Close
  512.         End If
  513.         End
  514.     End If
  515.     End If
  516. End Sub
  517. Sub cmdTranslate_Click ()
  518.   Dim Msg, LogMsg
  519.   Dim StVal
  520.   If gRunning Then Beep: Exit Sub
  521.   Dim Looper As Integer
  522.   Dim filelength As Long
  523.   Dim StartTime, FinTime
  524.   Dim InFileLine As String
  525.   Dim InLineCount As Integer
  526.   Dim OutlineCount As Integer
  527.   Dim ErrFileNum As Integer
  528.   Dim BadLineCount As Integer
  529.   Dim GraphUnit As Integer
  530.   lblElapsedTime.Visible = False
  531.   lblDBCount.Visible = False
  532.   lblRecCount = ""
  533.   If ReplaceMode > 2 Then ValidateMode345Key
  534.   On Error GoTo FileOpenError
  535.   'setup for reading records
  536.   InFileNum = FreeFile
  537.   Open lblCurrInput For Input As InFileNum Len = 500
  538.   filelength = LOF(InFileNum)
  539.   GraphUnit = ((filelength / RecordLen) / 50) + 1
  540.   If GraphUnit > 100 Then GraphUnit = 100
  541.   Screen.MousePointer = 11   ' cursor hourglass
  542.   LogMsg = "starting processing..." & NL
  543.   LogMsg = LogMsg & "ReplaceMode is " & ReplaceMode & NL
  544.   If ReplaceMode > 3 Then
  545.     LogMsg = LogMsg & "Mode345Key is " & Mode345Key() & " (" & gIOFld(Mode345Key()).dbName & ")" & NL
  546.     LogMsg = LogMsg & "Mode45Index is " & Mode45Index() & NL
  547.   End If
  548.   LogMsg = LogMsg & "ASCII input from: " & lblCurrInput & NL
  549.   LogMsg = LogMsg & "updated database: " & lblCurrDatabase & NL
  550.   LogMsg = LogMsg & "to table named  : " & lblCurrTable & NL
  551.   Logline LogMsg
  552.   ReadyDatabase      'depends on ReplaceMode 0/12345
  553.   ReadyTable         'depends on ReplaceMode 01/2345
  554.   gRunning = True   'so we can check before allowing exit
  555.   pnlStatus = "processing input records... ": DoEvents
  556.   Gauge1.Visible = True
  557.   On Error GoTo ErrorLogEntry
  558.   StartTime = Timer
  559.   ' init local variables
  560.   InLineCount = 0
  561.   OutlineCount = 0
  562.   BadLineCount = 0
  563.   Do While Not EOF(InFileNum)
  564.     InLineCount = InLineCount + 1
  565.       If InLineCount Mod GraphUnit = 0 Then
  566.     Gauge1.Value = Int((Loc(InFileNum) * 128 / filelength) * 100)
  567.       lblRecCount = InLineCount & " read " & BadLineCount & " errs"
  568.       DoEvents
  569.       End If
  570.     DoEvents
  571.     Line Input #InFileNum, InFileLine
  572.     If PassFilter(InFileLine) Then
  573.       AddNewOrSeekEdit (InFileLine)   'depends on ReplaceMode
  574.       If ReplaceMode = 3 Then
  575.     If OutlineCount + BadLineCount = 0 Then CheckBlockDeleteKey (InFileLine)
  576.       End If
  577.       If Len(InFileLine) <> RecordLen Then
  578.     Msg = "Line too short or too long (check for tabs)" & NL
  579.     Error (32767)
  580.       End If
  581.       For Looper = 1 To UBound(gIOFld)
  582.     Msg = ""
  583.     StVal = Mid(InFileLine, gIOFld(Looper).inStart, gIOFld(Looper).inLength)
  584.     gTabOut(gIOFld(Looper).dbName) = IIf(gIOFld(Looper).dbType < 10 And Trim(StVal) = "", Null, StVal)
  585.       Next
  586.       gTabOut.Update
  587.       OutlineCount = OutlineCount + 1
  588. ErrorResume:
  589.     End If
  590.   Loop
  591.   Gauge1.Visible = False
  592.   FinTime = Timer
  593.   lblElapsedTime.Visible = True
  594.   lblDBCount.Visible = True
  595.   lblElapsedTime = "elapsed: " & Int(FinTime - StartTime) & " sec" & NL
  596.   Msg = "operation finished" & NL
  597.   Msg = Msg & "table load time: " & Int(FinTime - StartTime) & " sec" & NL
  598.   lblDBCount = OutlineCount & " recs saved"
  599.   Msg = Msg & OutlineCount & " recs saved" & NL
  600.   lblRecCount = InLineCount & " read " & BadLineCount & " errs"
  601.   Msg = Msg & InLineCount & " read " & BadLineCount & " errs" & NL
  602.   Logline Msg
  603.   pnlStatus = "closing files...": DoEvents
  604.   Close InFileNum: gTabOut.Close : thisDb.Close
  605.   Screen.MousePointer = 0    ' cursor normal
  606.   pnlStatus = "done; log file " & localErrFileName: DoEvents
  607.   gRunning = False
  608.   Exit Sub
  609. FileOpenError:
  610.   Msg = Err & " " & Error & NL
  611.   Msg = Msg & " on opening ascii input file"
  612.   MsgBox Msg
  613.   End
  614. ErrorLogEntry:
  615.   LogError BadLineCount, Msg, InLineCount, InFileLine
  616.   Resume ErrorResume
  617.   Exit Sub
  618. End Sub
  619. Sub Form_Load ()
  620.     ' ASC2MDB: a tool to transfer ASCII records
  621.     '  into MS ACCESS format .MDB files.
  622.     '* Input ASCII records must all be the same length
  623.     '  (exceptions are written to the ERROR log)
  624.     '* Input records must also be uniformly laid out,
  625.     '  so that fields are located in the same position
  626.     '  in each record.
  627.     '* The .MDB file may or may not already exist.
  628.     '* If it exists, you can choose to preserve other
  629.     '  Tables in the MDB, and replace only the current
  630.     '  Table... or replace the entire MDB file.
  631.     '* requires Visual Basic 3 Professional Edition.
  632.     '  You can make an EXE easily for each specific
  633.     '  translation job
  634.     '===============================================
  635.     'Code modules:
  636.     '  GENERAL.FRM
  637.     '   the startup form, generalized routines only
  638.     ' & Includes validation routines that validate
  639.     '   most of the error-prone parameters you
  640.     '   can set in SPECIFIC.BAS.
  641.     '  GLOBALS.BAS
  642.     '   database globals and a few code globals that
  643.     '   should NOT need to be changed for each job
  644.     '  SPECIFIC.BAS  **CUSTOMIZE ONLY THIS FILE**
  645.     '   isolates all the job specific pieces (hopefully)
  646.     '   change the contents of each Sub, and
  647.     '   the declarations, but don't change the names of
  648.     '   the subroutines... see comments in SPECIFIC.BAS
  649.     '  ARGV.BAS
  650.     '   routines for parsing COMMAND (cmd line)
  651.     '   using this allows some flexibility without having
  652.     '   to recompile --
  653.     '   (only the default "input" and "output"
  654.     '     fnames at Sept/93)
  655.     '   (potentially everything in SPECIFIC.BAS could
  656.     '     be fed in thru command line/data files)
  657.     ' In a nutshell: SPECIFICS.BAS isolates
  658.     ' all the items SPECIFIC to your file/job.
  659.     ' You shouldn't have to change anything else but
  660.     ' the routines in that file.  These routines control
  661.     ' the following:  (see module comments)
  662.     ' DATABASE file path
  663.     ' REPLACEMODE variable
  664.     '  - see the specific project .BAS file,
  665.     '       SetupSpecifics routine
  666.     '  - do we replace entire Database .mdb file?
  667.     '     or just replace the entire Table in the .mdb?
  668.     '     or just certain records in the Table?
  669.     ' TABLE name
  670.     ' FIELD parameters:
  671.     '  - how to setup each field in the table
  672.     '  - where to find each field in the input
  673.     '    ASCII file.
  674.     ' INDEX parameters
  675.     ' DEFAULT PATHNAMES for the input ASCII file and
  676.     '    the output MDB file, and for an Error log
  677.     '    of Update errors
  678.     Dim Msg
  679.     gRunning = True    'for testing at cmdExit_click, cmdTranslate_click
  680.     GlobalInit         'initialization, global.bas
  681.     NL = Chr(13) & Chr(10)
  682.     Form1.Show
  683.     SetupSpecifics   ' job specifics see in project .BAS
  684.     Caption = App.Title
  685.     CheckFields
  686.     CheckIndexes
  687.     ' decide which radio button for Replace mode
  688.     pnlStatus = "collecting parameters...": DoEvents
  689.     argvInit
  690.     'see if we are running with a command line
  691.     ' if so, use the values from the command line
  692.     ' instead of the programmed values
  693.     If argc = 5 Then
  694.     lblCurrInput = argv(1).Value
  695.     lblCurrDatabase = argv(2).Value
  696.     lblCurrTable = argv(3).Value
  697.     localErrFileName = argv(4).Value
  698.     ReplaceMode = argv(5).Value
  699.     If ReplaceMode > 5 Or ReplaceMode < 0 Then
  700.       Msg = "Command Line ReplaceMode parameter out of range." & NL
  701.       Msg = Msg & "Resetting to 0."
  702.       MsgBox Msg
  703.       ReplaceMode = 0
  704.     End If
  705.     Else
  706.     lblCurrInput = gcDefInputName
  707.     lblCurrDatabase = gcDefDbName
  708.     lblCurrTable = gcTable
  709.     localErrFileName = gcErrFileName
  710.     End If
  711.     'check if error file name is okay before we start
  712.     Logline "beginning run" & NL
  713.     lblReplaceMode = ReplaceModes(ReplaceMode)
  714.     If argc <> 0 And argc <> 5 Then MsgBox ("check number of cmd line args!")
  715.     pnlStatus = "ready...": DoEvents
  716.     gRunning = False    'for testing at cmdExit_click, cmdTranslate_click
  717. End Sub
  718. Sub LogError (BadLineCount, InMsg, InLineCount, InFileLine)
  719.     Dim FileNum
  720.     BadLineCount = BadLineCount + 1
  721.     FileNum = FreeFile
  722.     Open localErrFileName For Append As FileNum Len = 300
  723.     'this slows things down if excessive errors...
  724.           'that's fine, user might notice and abort!
  725.     Dim LogMsg
  726.     LogMsg = Date & " " & Time & NL
  727.     Select Case BadLineCount
  728.     Case gbErrorLimit + 1
  729.     LogMsg = LogMsg & "over " & gbErrorLimit & "errors, no more logging"
  730.     Print #FileNum, LogMsg
  731.     Close FileNum
  732.     Case Is <= gbErrorLimit
  733.     LogMsg = LogMsg & InMsg
  734.     LogMsg = LogMsg & Err & " " & Error & NL
  735.     LogMsg = LogMsg & " BAD LINE, line " & InLineCount & NL
  736.     LogMsg = LogMsg & " of input file " & lblCurrInput & NL
  737.     LogMsg = LogMsg & InFileLine & NL
  738.     LogMsg = LogMsg & "-----" & NL
  739.     Print #FileNum, LogMsg
  740.     Close FileNum
  741.     Case Is > gbErrorLimit
  742.     Close FileNum
  743.     End Select
  744. End Sub
  745. Sub Logline (InMsg)
  746.     Dim FileNum
  747.     Dim Msg
  748.     Dim LogMsg
  749.     On Error GoTo BadErrLog
  750.     FileNum = FreeFile
  751.     If AscErrorFlag = False Then
  752.     AscErrorFlag = True  'used to flag whether ErrFile
  753.                  'is already assigned
  754.     Open localErrFileName For Output As FileNum Len = 300
  755.     Else
  756.     Open localErrFileName For Append As FileNum Len = 300
  757.     End If
  758.     LogMsg = Date & " " & Time & NL
  759.     LogMsg = LogMsg & InMsg
  760.     LogMsg = LogMsg & "-----" & NL
  761.     Print #FileNum, LogMsg
  762.     Close FileNum
  763.     Exit Sub
  764. BadErrLog:
  765.   Msg = Err & " " & Error & NL
  766.   Msg = Msg & "on opening log file." & NL
  767.   Msg = Msg & "Probably: bad error log File Name." & NL
  768.   Msg = Msg & "Check error log file name assigned in your code." & NL
  769.   Msg = Msg & " or assigned in on the command line." & NL
  770.   MsgBox Msg
  771.   If Not gTabOut Is Nothing Then gTabOut.Close : thisDb.Close
  772.   End
  773. End Sub
  774. Sub mnuEditInput_Click ()
  775.     Dim miSpot As Integer  'locate "\" char
  776.     Dim miIndex As Integer 'locate "\" char
  777.     pnlStatus = "collecting parameters...": DoEvents
  778.     miSpot = 1
  779.     Do                      'locate "\" char
  780.     miIndex = miSpot + 1
  781.     miSpot = InStr(miIndex, lblCurrInput, "\")
  782.     Loop Until miSpot = 0
  783.     cmdlg1.InitDir = Left$(lblCurrInput, miIndex - 2)
  784.     cmdlg1.Filename = lblCurrInput
  785.     cmdlg1.DialogTitle = "ASCII file to process"
  786.     cmdlg1.Filter = "All Files (*.*)|*.*|Text files (*.txt)|*.txt"
  787.     cmdlg1.Flags = OFN_HIDEREADONLY Or OFN_FILEMUSTEXIST
  788.     cmdlg1.Action = 1
  789.     lblCurrInput = LCase$(cmdlg1.Filename)
  790.     pnlStatus = "ready...": DoEvents
  791. End Sub
  792. Sub mnuEditMDB_Click ()
  793.     Dim miSpot As Integer   'locate "\" char
  794.     Dim miIndex As Integer  'locate "\" char
  795.     pnlStatus = "collecting parameters...": DoEvents
  796.     miSpot = 1
  797.     Do                      'locate "\" char
  798.     miIndex = miSpot + 1
  799.     miSpot = InStr(miIndex, lblCurrDatabase, "\")
  800.     Loop Until miSpot = 0
  801.     cmdlg1.InitDir = Left$(lblCurrDatabase, miIndex - 2)
  802.     cmdlg1.Filename = lblCurrDatabase
  803.     cmdlg1.DialogTitle = "Store in .MDB database file"
  804.     cmdlg1.Filter = "MDB files (*.mdb)|*.mdb|All Files (*.*)|*.*"
  805.     cmdlg1.Flags = OFN_HIDEREADONLY
  806.     If ReplaceMode = 0 Then
  807.     cmdlg1.Flags = cmdlg1.Flags Or OFN_CREATEPROMPT Or OFN_OVERWRITEPROMPT
  808.     Else
  809.     cmdlg1.Flags = cmdlg1.Flags Or OFN_FILEMUSTEXIST
  810.     End If
  811.     cmdlg1.Action = 2
  812.     lblCurrDatabase = LCase$(cmdlg1.Filename)
  813.     pnlStatus = "ready...": DoEvents
  814. End Sub
  815. Sub mnuEditReplMode_Click ()
  816.   FrmReplaceMode.Show 1
  817. End Sub
  818. Sub mnuEditTable_Click ()
  819.   On Error Resume Next
  820.   frmSelTable.Show 1
  821.   pnlStatus = "ready...": DoEvents
  822. End Sub
  823. Sub mnuFileExit_Click ()
  824.     cmdExit_Click
  825. End Sub
  826. Sub mnuHelpAbout_Click ()
  827.    AboutFrm.Show 1
  828. End Sub
  829. Sub mnuHelpContents_Click ()
  830.   Dim Msg
  831.   Msg = "Creates .mdb files, tables, and/or records from ASCII input files." & NL
  832.   Msg = Msg & "Read the file ASC2MDB.TXT for more information." & NL & NL
  833.   Msg = Msg & "Tip: you can change the runtime defaults without changing " & NL
  834.   Msg = Msg & " code or recompiling - use commandline options, see docs. " & NL & NL
  835.   Msg = Msg & "Help on Replace Mode is under Edit, Replace Mode. " & NL & NL
  836.   Msg = Msg & "
  837.  1993 Richard Curzon -- CIS 71371,2521 " & NL
  838.   Msg = Msg & "all rights reserved - code may be freely used but" & NL
  839.   Msg = Msg & " but may not be sold for profit in whole or in part." & NL
  840.   MsgBox Msg
  841. End Sub
  842. Sub NewDatabase ()
  843.     Dim strOldTest As String
  844.     Dim Msg
  845.     'kill old database file if any
  846.     On Error GoTo NDError
  847.     strOldTest = Dir(lblCurrDatabase)
  848.     On Error GoTo 0
  849.     If Len(strOldTest) <> 0 Then
  850.     pnlStatus = "deleting old database...": DoEvents
  851.     Kill lblCurrDatabase
  852.     End If
  853.     'create the new database file
  854.     pnlStatus = "creating new database...": DoEvents
  855.     Set thisDb = CreateDatabase(lblCurrDatabase, DB_LANG_GENERAL, 0)
  856.     Exit Sub
  857. NDError:
  858.     Msg = "Error:" & NL
  859.     Msg = Msg & Err & " : " & Error & NL
  860.     Msg = Msg & "In New Database creation"
  861.     MsgBox Msg
  862.     End
  863. End Sub
  864. Sub ReadyDatabase ()
  865.     Dim Msg
  866.     If ReplaceMode = 0 Then
  867.     pnlStatus = "creating new database...": DoEvents
  868.     On Error GoTo MakeDbError
  869.     NewDatabase
  870.     On Error GoTo 0
  871.     Else
  872.     pnlStatus = "opening existing database...": DoEvents
  873.     On Error GoTo OpenDbError
  874.     Set thisDb = OpenDatabase(lblCurrDatabase, True)
  875.     On Error GoTo 0
  876.     End If
  877.     Exit Sub
  878. MakeDbError:
  879.     Msg = Err & " " & Error & NL
  880.     Msg = Msg & " on trying to create the mdb file"
  881.     MsgBox Msg
  882.     End
  883.     Exit Sub
  884. OpenDbError:
  885.     Msg = Err & " " & Error & NL
  886.     Msg = Msg & " on trying to open the mdb file"
  887.     MsgBox Msg
  888.     End
  889. End Sub
  890. Sub ReadyTable ()
  891.     Dim Msg
  892.     Dim Ind As Integer, Looper As Integer
  893.     On Error GoTo NoOldTable
  894.     'clear old table if it's there...
  895.     If ReplaceMode <= 1 Then
  896.     Dim NewTab As New TableDef
  897.     Dim NewIdx As New Index
  898.     Dim NewFld As New field
  899.     If ReplaceMode = 1 Then
  900.       Msg = "deleting existing table..."
  901.       pnlStatus = Msg: DoEvents
  902.       On Error Resume Next
  903.       thisDb.TableDefs.Delete lblCurrTable
  904.       On Error GoTo 0
  905.     End If
  906.     Msg = "creating new table..."
  907.     pnlStatus = Msg: DoEvents
  908.     NewTab.Name = lblCurrTable  ' Set the table name.
  909.     ' Append Fields.
  910.     Ind = UBound(gIOFld)
  911.     Msg = "appending the fields..."
  912.     pnlStatus = Msg: DoEvents
  913.     For Looper = 1 To Ind  ' Set properties for fields.
  914.         NewFld.Name = gIOFld(Looper).dbName
  915.         NewFld.Type = gIOFld(Looper).dbType
  916.         NewFld.Size = gIOFld(Looper).dbSize
  917.         NewTab.Fields.Append NewFld
  918.         Set NewFld = Nothing
  919.     Next Looper
  920.     ' Append Indexes
  921.     Ind = UBound(gIndexPtrn)
  922.     Msg = "appending indexes..."
  923.     pnlStatus = Msg: DoEvents
  924.     For Looper = 1 To Ind  ' Set properties for fields.
  925.         NewIdx.Name = gIndexPtrn(Looper).Name
  926.         NewIdx.Fields = gIndexPtrn(Looper).Fields
  927.         NewIdx.Primary = gIndexPtrn(Looper).Primary
  928.         NewIdx.Unique = gIndexPtrn(Looper).Unique
  929.         NewTab.Indexes.Append NewIdx
  930.         Set NewIdx = Nothing
  931.     Next Looper
  932.     ' Append Table creating all objects.
  933.     Msg = "appending table, creating physical objects..."
  934.     pnlStatus = Msg: DoEvents
  935.     thisDb.TableDefs.Append NewTab
  936.     End If
  937.     Msg = "opening the table..."
  938.     pnlStatus = Msg: DoEvents
  939.     Set gTabOut = thisDb.OpenTable(lblCurrTable)
  940.     On Error GoTo 0
  941.     Exit Sub
  942. NoOldTable:
  943.     Msg = Msg & NL & "Error:" & NL
  944.     Msg = Msg & Err & " : " & Error & NL
  945.     Msg = Msg & "Trying to ready the database table... please check"
  946.     MsgBox Msg
  947.     End
  948. End Sub
  949. Sub ValidateMode345Key ()
  950.     Dim Msg
  951.     On Error GoTo VMKeyError
  952.     Select Case Mode345Key()
  953.     Case 1 To UBound(gIOFld)
  954.     Case Else
  955.     Msg = "Invalid Mode345Key Function!"
  956.     Error 32000
  957.     End Select
  958.     On Error GoTo 0
  959.     Exit Sub
  960. VMKeyError:
  961.     MsgBox Msg
  962.     End
  963. End Sub
  964.